﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    class Game
    {
        private const int GameWidth = 592;
        private const int GameHeight = 455;
        private System.Timers.Timer Timer { get; set; }
        private Bar _bar;
        private pacman _pacman;
        private money _money;
        public Game()
        {
            _bar = new Bar();
            _pacman = new pacman(new Rectangle(300,300, 50, 50));
            _money = new money(new Rectangle(10, 10, 20,20));
            //初始化时钟
            Timer = new System.Timers.Timer();
            Timer.Elapsed += Timer_Elapsed;
            Timer.Start();
        }
        private void Timer_Elapsed(object sender,System.Timers.ElapsedEventArgs e)
        {
            //时钟处理程序
        }
        /// <summary>
        /// 绘图游戏场景
        /// </summary>
        /// <param name="g"></param>
        /// <param name="size"></param>
        public void Draw(Graphics g, Size size)
        {
            //定义空白的图
            Image img = new Bitmap(GameWidth, GameHeight);

            Graphics _g = Graphics.FromImage(img);
            Rectangle rec = new Rectangle(new Point(0, 0), new Size(GameWidth, GameHeight));

            _g.DrawImage(Properties.Resources.bg, rec);
            _pacman.Draw(_g);
            _bar.Draw(_g);
            _money.Draw(_g);

            //todo

            g.DrawImage(img, new Rectangle(new Point(0, 0), size));
        }

        /// <summary>
        /// 处理键盘
        /// </summary>
        /// <param name="key"></param>
        public void KeyDown(String key)
        {
            _pacman.KeyDown(key);
        }
    }
}
